﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DBUtilitySqlsever;
using STOPPLANService.Untity;

namespace STOPPLANService
{
   public class STOPPLANOracle
    {
       Makelog log = new Makelog();
       STOPPLANMes mes = new STOPPLANMes();
       /// <summary>
       /// 添加办成品方法
       /// </summary>
       /// <param name="stview"></param>
       /// <returns></returns>
       public int insertMaterialShutDown(STOPPLANS stview)
       {

           int falg = 0;
           string sql = "insert into materialshutdown (machineid, shutdownstart, shutdowntime, inpcomment, updatedate) values ('" + stview.MCHID + "','"+stview.PLANSTIM+"','"+stview.planUseTime+"','"+stview.ITYPENAM+"','"+DateTime.Now.ToString("yyyyMMddhhmm")+"')";

           try
           {
               falg = DBUtilityOracle.DBUtilityOra.ExecuteSql(sql.ToString());
              
           }
           catch(Exception ex)
           {
               string sql1 = "insert into Deletetab(FAC, MCHID, ITYPENAM, INAM, PLANSTIM, planUseTime) values ('" + stview.FAC + "','" + stview.MCHID + "','" + stview.ITYPENAM + "','" + stview.INAM + "','" + stview.PLANSTIM + "','" + stview.planUseTime + "')";
               int num = DbHelperSQL.ExecuteSql(sql1.ToString());
               log.MakeLog(2, "同步半成品失败信息", stview.MCHID + ";" + stview.PLANSTIM);
               log.MakeLog(2,"同步半成品数据服务失败",ex.ToString());
           }
           
           return falg;
       }
       /// <summary>
       /// 添加硫化及成型
       /// </summary>
       /// <param name="stview"></param>
       /// <returns></returns>
       public int insertCureBuildingShutDown(STOPPLANS stview)
       {

           int falg = 0;
           string sql = "insert into curebuildingshutdown(groupid, machinename, shutdownyyyy, shutdownmmdd, shutdownhhmm, shutdowntime, inpcomment, reason) values ('" + stview.FACNO + "','" + stview.MCHID + "','" + stview.PLANSTIM.Substring(0, 4) + "','" + stview.PLANSTIM.Substring(4, 4) + "','" + (stview.PLANSTIM).Substring(8,4) + "','" + stview.planUseTime + "','" + stview.ITYPENAM + "','" + stview.INAM + "')";

           try
           {
               falg = DBUtilityOracle.DBUtilityOra.ExecuteSql(sql.ToString());
              
           }
           catch (Exception ex)
           {
               string sql1 = "insert into Deletetab(FAC, MCHID, ITYPENAM, INAM, PLANSTIM, planUseTime) values ('" + stview.FAC + "','" + stview.MCHID + "','" + stview.ITYPENAM + "','" + stview.INAM + "','" + stview.PLANSTIM + "','" + stview.planUseTime + "')";
               int num = DbHelperSQL.ExecuteSql(sql1.ToString());
               log.MakeLog(2, "同步硫化及成型信息", stview.MCHID + ";" + stview.PLANSTIM);
               log.MakeLog(2, "同步硫化及成型数据服务失败", ex.ToString());
           }
           
           return falg;
       }
    }
}
